package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.PageDomain;
import com.zzyl.nursing.dto.DeviceDataListDto;
import com.zzyl.nursing.dto.FamilyElderDto;
import com.zzyl.nursing.dto.RegisterDeviceRequest;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.ElderBedDeviceVo;
import com.zzyl.nursing.vo.FamilyMemberElderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author mr.wu
 * @date 2025-05-23
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberElderController extends BaseController {
    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    /**
     * 绑定家人
     *
     * @param request
     * @param dto
     * @return
     */
    @ApiOperation("绑定家人")
    @PostMapping("/add")
    public AjaxResult familyElderadd(HttpServletRequest request, @RequestBody FamilyElderDto dto) {
        String token = request.getHeader("authorization");
        familyMemberElderService.familyElderadd(token, dto);
        return success();
    }

    /**
     * 根据id解绑数据
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam Long id){
        familyMemberElderService.deleteById(id);
        return success();
    }

    /**
     * 家人列表
     *
     * @return
     */
    @ApiOperation("家人列表")
    @GetMapping("/my")
    public AjaxResult familyElderMy() {
        List<FamilyMemberElderVo> familyMemberVoList = familyMemberElderService.familyElderMy();
        return success(familyMemberVoList);
    }

    /**
     * 家人列表
     *
     * @return
     */
    @ApiOperation("家人列表")
    @GetMapping("/list-by-page")
    public AjaxResult familyElderpage(HttpServletRequest request, PageDomain pageDomain) {
        String token = request.getHeader("authorization");
        List<ElderBedDeviceVo> elderBedDeviceVoList = familyMemberElderService.familyElderpage(token, pageDomain);
        return success(elderBedDeviceVoList);
    }

    /**
     * 查询健康数据
     *
     * @return
     */
    @ApiOperation("查询健康数据")
    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody RegisterDeviceRequest deviceRequest) {

        return familyMemberElderService.QueryDevicePropertyStatus(deviceRequest.getDeviceName(), deviceRequest.getProductKey());
    }

    /**
     * 按天统计查询指标数据
     *
     * @return
     */
    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(DeviceDataListDto dto) {
                return familyMemberElderService.queryDeviceDataListByDay(dto);
    }
    /**
     * 按天统计查询指标数据
     *
     * @return
     */
    @ApiOperation("按天统计查询指标数据")
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(DeviceDataListDto dto) {
        return familyMemberElderService.queryDeviceDataListByWeek(dto);
    }
}
